//
//  CreateShareIncubationSpaceController.m
//  BigToBig
//
//  Created by yi liu on 16/8/5.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "CreateShareIncubationSpaceController.h"

@interface CreateShareIncubationSpaceController ()
<
UITableViewDelegate,
UITableViewDataSource
>
@property (nonatomic , strong)NSArray *sectionArr;
@property (nonatomic , strong)NSArray *companyArr;
@property (nonatomic , strong)NSArray *updateArr;
@property (nonatomic , strong)NSArray *focusArr;
@property (nonatomic , strong)NSMutableDictionary *dataDic;
@property (nonatomic , strong)UITableView *mainTableView;
@property (nonatomic , assign)BOOL isSureButtonSelected;

@end

@implementation CreateShareIncubationSpaceController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.navigationController setNavigationBarHidden:NO animated:YES];
    
    // Do any additional setup after loading the view.
    UILabel *titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 100, 40)];
    titleLab.text = @"共享孵化空间";
    titleLab.textColor = [UIColor whiteColor];
    [self setBackBar];
    titleLab.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLab;
    self.navigationController.navigationBar.barTintColor = COLOR_RGBA(77, 155, 255, 1);
    [self initDataSource];
    [self createView];

}
- (void)createView{
    self.mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStyleGrouped];
    self.mainTableView.rowHeight = 70;
    self.mainTableView.showsVerticalScrollIndicator = NO;
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    [self.mainTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:NSStringFromClass([UITableViewCell class])];
    [self.view addSubview:self.mainTableView];
}

#pragma mark 导航栏左右Button
- (void)setBackBar{
    
    BackButton *backBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 44, 44);
    [backBtn addTarget:self action:@selector(backController:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
    
    BackButton *saveBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    saveBtn.frame = CGRectMake(kScreenWidth - 44,0 , 44, 40);
    [saveBtn addTarget:self action:@selector(SaveMessage) forControlEvents:UIControlEventTouchUpInside];
    [saveBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [saveBtn setTitle:@"提交" forState:UIControlStateNormal];
    [saveBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:saveBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
}
#pragma mark 返回
- (void)backController:(UIButton *)button{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 提交
- (void)SaveMessage{
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"继续完善内容" message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        [self.navigationController dismissViewControllerAnimated:alert completion:nil];
    }];
    UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        ProjectInfoViewController *pro = [ProjectInfoViewController alloc];
        [self.navigationController pushViewController:pro animated:YES];
    }];
    
    [alert addAction:cancel];
    [alert addAction:ok];
    [self.navigationController
     presentViewController:alert animated:YES completion:nil];
    
}
- (void)initDataSource{
    
    self.sectionArr = [[NSArray alloc] initWithObjects:@"1",@"2",@"3", nil];
    
    NSDictionary *dic00 = [[NSDictionary alloc] initWithObjectsAndKeys:@"公司电话",@"name",@"请填写",@"content", nil];
    NSDictionary *dic01 = [[NSDictionary alloc] initWithObjectsAndKeys:@"公司名称",@"name",@"请填写",@"content", nil];
    
    NSDictionary *dic02 = [[NSDictionary alloc] initWithObjectsAndKeys:@"公司地点",@"name",@"请填写",@"content", nil];
    self.companyArr = [[NSArray alloc] initWithObjects:dic00,dic01,dic02, nil];
    
    NSDictionary *dic10 = [[NSDictionary alloc] initWithObjectsAndKeys:@"上传身份证",@"name",@"点击上传",@"content", nil];
    
    NSDictionary *dic11 = [[NSDictionary alloc] initWithObjectsAndKeys:@"注册资本证明",@"name",@"点击上传",@"content", nil];

    self.updateArr = [[NSArray alloc] initWithObjects:dic10,dic11, nil];
    
    
    NSDictionary *dic20 = [[NSDictionary alloc] initWithObjectsAndKeys:@"备注信息",@"name",@"请填写信息",@"content", nil];
    
    self.focusArr = [[NSArray alloc] initWithObjects:dic20, nil];
    
    _dataDic = [[NSMutableDictionary alloc]initWithObjectsAndKeys:_companyArr,[_sectionArr objectAtIndex:0],_updateArr,[_sectionArr objectAtIndex:1],_focusArr,[_sectionArr objectAtIndex:2],nil];
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return _sectionArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (section == 0) {
        return _companyArr.count;
    }if (section == 1) {
        return _updateArr.count;
    }if (section == 2) {
        return _focusArr.count;
    }
    return 0;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0 || section == 1|| section == 2) {
        return 15;
    }
    return 0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    if (section == 0) {
        return 0.001f;
    }
    return 60;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *str = [_sectionArr objectAtIndex:indexPath.section];
    NSArray *arr = [_dataDic objectForKey:str];
    
    static NSString *CellIdentifier = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    cell = nil;
    if (cell == nil) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    UILabel *userLabel=[[UILabel alloc]initWithFrame:CGRectMake(30, 0, kScreenWidth, 70)];
    userLabel.text=[[arr objectAtIndex:indexPath.row] valueForKey:@"name"];
    [cell.contentView addSubview:userLabel];
    
    UILabel *contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(kScreenWidth / 2 - 20, 0, kScreenWidth / 2 - 10, 70)];
    contentLabel.text = [[arr objectAtIndex:indexPath.row] valueForKey:@"content"];
    contentLabel.textAlignment = NSTextAlignmentRight;
    contentLabel.font = [UIFont systemFontOfSize:15];
    contentLabel.textColor = [UIColor colorWithWhite:0.827 alpha:1.000];
    [cell.contentView addSubview:contentLabel];
    
    
    return cell;
    
    
}

//#pragma mark 让分区标题随tableView滚动
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//    
//    CGFloat sectionHeaderHeight = 20;
//    
//    if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
//        
//        scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
//        
//    } else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
//        
//        scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
//        
//    }
//    
//    CGFloat sectionFootHeight = 60;
//    
//    if (scrollView.contentOffset.y >= sectionFootHeight && scrollView.contentOffset.y < 60) {
//        scrollView.contentInset = UIEdgeInsetsMake(0, 0, -60, 0);
//    }else if (scrollView.contentOffset.y == -60) {
//        
//        scrollView.contentInset = UIEdgeInsetsMake(60, 0, 0, 0);
//        
//    }
//    else if (scrollView.contentOffset.y < 0 &&scrollView.contentOffset.y != -64){
//        scrollView.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);
//    }
//    else if (scrollView.contentOffset.y >= 23 && scrollView.contentOffset.y <= 83){
//        scrollView.contentInset = UIEdgeInsetsMake(0, 0, -(83-scrollView.contentOffset.y), 0);
//        
//    }
//    
//}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor colorWithWhite:0.949 alpha:1.000];
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.textColor = [UIColor grayColor];
    titleLabel.numberOfLines = 0;
    titleLabel.font = [UIFont systemFontOfSize:14];
    [view addSubview:titleLabel];
    if (section == 1) {
        view.frame = CGRectMake(0, 0, kScreenWidth, 50);
        titleLabel.frame = CGRectMake(10, 0, kScreenWidth - 20, 60);
        titleLabel.text = @"请上传清晰证件正反面,最多上传二张图片, 上传图片格式为(JPG. PNG ). 上传文件小于5MB";
    }if (section == 2) {
        UIButton *sure = [UIButton buttonWithType:UIButtonTypeCustom];
        sure.selected = self.isSureButtonSelected;
        sure.frame = CGRectMake(10, 10, 25, 25);
        [view addSubview:sure];
        [sure setImage:[UIImage imageNamed:@"xuanzhong"] forState:UIControlStateSelected];
        [sure setImage:[UIImage imageNamed:@"weixuanzhong"] forState:UIControlStateNormal];
        [sure addTarget:self action:@selector(time1:) forControlEvents:UIControlEventTouchUpInside];
        UILabel *word = [[UILabel alloc] initWithFrame:CGRectMake(sure.maxX, 10, kScreenWidth - 50, 50)];
        word.text = @"我承诺以上所有登记的内容都是绝对真实的,并对因一切虚假信息产生的后果负全责,我已了解和同意《大秀创投提供的服务》以及《大秀创投创业融资服务协议》.";
        word.textColor = [UIColor lightGrayColor];
        word.font = [UIFont systemFontOfSize:11];
        word.numberOfLines = 0;
        [view addSubview:word];
    }
    
    return view;
}
- (void)time1:(UIButton *)btn{
    btn.selected = !btn.selected;
    self.isSureButtonSelected = btn.selected;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
